package com.example.summary.lianbiao;

/**
 * Created by wzn on 2019/3/29.
 */
public class LianBIaoDelete {

    public static void main(String[] args) {
        LianBiaoNode node = new LianBiaoNode(1, new LianBiaoNode(2, new LianBiaoNode(3
                , new LianBiaoNode(4
                , new LianBiaoNode(5, new LianBiaoNode(6
                , new LianBiaoNode(7, new LianBiaoNode(8
                , new LianBiaoNode(9, new LianBiaoNode(10, null))))))))));
        delete(2,node);
        while (null != node) {
            System.out.println(node.getI());
            node = node.getNext();
        }
    }

    private static LianBiaoNode delete(int x, LianBiaoNode node) {
        LianBiaoNode begin = node;
        LianBiaoNode next = node;

        for (int i = 0; i < x; i++) {
            next = next.getNext();
        }

        while (next.getNext() != null) {
            next = next.getNext();
            begin = begin.getNext();
        }

        begin.setNext(begin.getNext().getNext());
        return node;
    }
}
